package com.rdgzs.framework.utilsTools;
  
import java.text.SimpleDateFormat;   
import java.util.Date;   

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;


public class JsonDateFormat implements JsonValueProcessor  {
	private String  datePattern="";
	private SimpleDateFormat   dateFormat ;   
	public JsonDateFormat(String  datePattern) {
		this.datePattern=datePattern;
		this.dateFormat= new SimpleDateFormat(datePattern);
	}
	public JsonDateFormat(SimpleDateFormat  dateFormat) {
		this.dateFormat= dateFormat;
	}
	
    public Object processArrayValue(Object value, JsonConfig jsonConfig) {   
	    return process(value);   
	}   
	
	public Object processObjectValue(String key, Object value,   
	    JsonConfig jsonConfig) {   
	    return process(value);   
	}   
	
	private Object process(Object value) {  
		if(value==null){
			return null;
		}
	    return dateFormat.format((Date) value);   
	}

}   

